/**
 * Created by Administrator on 2017/4/15.
 */


var LogicSubModules = require("../logic/sub");

var exp = module.exports;

exp.getSubLogic = function(gameType) {
    return LogicSubModules[gameType];
}

exp.checkSceneRoomCoin = function (sceneConfig, coin) {
    if (!sceneConfig) {
        return Code.ROOM_SCENE_INVALID;
    }

    if (sceneConfig.minCoin && coin < sceneConfig.minCoin) {
        return Code.LACK_OF_COIN;
    }

    if (sceneConfig.maxCoin && coin >= sceneConfig.maxCoin) {
        return Code.COIN_MAX_LIMIT;
    }
}

exp.calcRoomMaxPlayer = function (subConfig, initArgs) {
    return subConfig.roomPlayerNum || initArgs.options.roomPlayerNum || 4;
}

exp.calcCreateRoomNeedResource = function(SubLogic, initArgs) {
    var needResource = SubLogic.Rule.calcCreateRoomNeedResource(initArgs);
    if (initArgs.hasOwnProperty("needResourceRate")) {
        ExObject.mul(needResource, initArgs.needResourceRate/100, Math.ceil);
    }
    if(initArgs['costMode'] == Def.RoomCostMode.AA) {
       // SubLogic.Config.SubType[this._subType]
        var playerNum = this.calcRoomMaxPlayer(SubLogic.Config.SubType[initArgs.subType], initArgs);
        needResource = ExObject.mulNew(needResource, 1/playerNum, Math.ceil);
    }
    return needResource;
}